#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <resolv.h>

int main() {
    const char *src = "SGVsbG8sIFdvcmxkIQ=="; // Base64编码的字符串
    size_t srclength = strlen(src);
    unsigned char *dst;
    size_t dstlength;

    // 计算需要的输出缓冲区大小
    dstlength = srclength * 3 / 4 + 3;
    dst = malloc(dstlength);
    if (dst == NULL) {
        fprintf(stderr, "Memory allocation failed\n");
        return 1;
    }

    // 执行Base64解码
    dstlength = b64_pton(src, dst, dstlength);
    if (dstlength == (size_t)-1) {
        fprintf(stderr, "Base64 decoding failed\n");
        free(dst);
        return 1;
    }

    // 将输出缓冲区的末尾设置为字符串结束符
    dst[dstlength] = '\0';

    printf("Decoded: %s\n", dst);

    free(dst);
    return 0;
}